﻿using System;
using System.Data;
using System.Text;
using BO.Infrastructure.StaticData;
using BO.Infrastructure.Utils;
using BO.News;

namespace GUI.Controls.Photo
{
    public partial class OtherPhoto : System.Web.UI.UserControl
    {

        private const int ImageWidth = 190;
        private const int ImageHeight = 105;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        internal bool DataBind(DataTable dt)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                var sb = new StringBuilder();
                var bo = NewsBO.GetInstance();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    var r = dt.Rows[i];
                    var avatar = PresentationUtils.Photo.BuildNewsAvatar(r, ImageWidth, ImageHeight);
                    string subTitle = string.Empty;
                    var zoneId = PresentationUtils.Object2Integer(r[SqlConstants.NewsPublish.ZoneId].ToString());
                    if (zoneId > 0)
                    {
                        var objCat = bo.GetCategoryDetail(zoneId);
                        if (objCat != null)
                            subTitle = objCat.Name;
                    }

                    sb.AppendFormat("<li {5}>{3}<a href=\"{0}\" title=\"{2}\">{1}</a><br /><label class=\"sub-title\">{4}</label></li>",
                    r[SqlConstants.NewsPublish.Url],
                    r[SqlConstants.NewsPublish.Title],
                    r[SqlConstants.NewsPublish.EncodedTitle],
                    avatar,
                    subTitle,
                    (i + 1) % 3 == 0 ? "class=\"last\"" : string.Empty
                    );
                }
                ltrData.Text = sb.ToString();
                return true;
            }
            return false;
        }
    }
}